package com.ysstech.kettle.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ysstech.common.entity.PageBean;
import com.ysstech.kettle.entity.JobCategory;
import com.ysstech.kettle.mapper.JobCategoryMapper;
import com.ysstech.kettle.service.JobCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 分类表 服务实现类
 * </p>
 *
 * @author lishuangliang
 * @since 2021-06-03
 */
@Service
public class JobJobCategoryServiceImpl extends ServiceImpl<JobCategoryMapper, JobCategory> implements JobCategoryService {
    /**
     * 查询采集分类表列表信息
     *
     * @param jobCategory
     * @param pageBean
     * @return
     * @throws Exception
     */
    public PageBean<JobCategory> queryAllCategory(JobCategory jobCategory, PageBean pageBean) throws Exception {
        QueryWrapper<JobCategory> wrapper = this.getQueryWrapper(jobCategory);
        IPage pageBalance = this.page(new Page<>(pageBean.getPageNum(), pageBean.getPageSize()), wrapper);
        this.switchedListCategory(pageBalance.getRecords());
        return new PageBean<>(pageBalance);
    }


    /**
     * 类型，机构等中文的转换
     *
     * @param list
     * @return
     * @throws Exception
     */
    public List<JobCategory> switchedListCategory(List<JobCategory> list) throws Exception {
        for (JobCategory jobCategory : list) {
            if (null == jobCategory) {
                continue;
            }
        }
        return list;
    }

    /**
     * 查询条件
     *
     * @param jobCategory
     * @return
     * @throws Exception
     */
    private QueryWrapper<JobCategory> getQueryWrapper(JobCategory jobCategory) throws Exception {
        QueryWrapper<JobCategory> wrapper = new QueryWrapper<>();
        if (null == jobCategory) {
            return wrapper;
        }
        if (StringUtils.isNotBlank(jobCategory.getCategoryName())) {
            wrapper.like("CATEGORY_NAME", jobCategory.getCategoryName());
        }
        wrapper.orderByAsc("SEQUENCE");
        return wrapper;
    }
}
